package com.ruoyi.xh.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TablePageDataInfo;
import com.ruoyi.common.core.domain.CommentResult;
import com.ruoyi.xh.domain.XhCity;
import com.ruoyi.xh.service.IXhCityService;

/**
 * 城市Controller
 *
 * @author songjw
 * @date 2024-12-13
 */
@Api(tags = "城市Controller",value = "城市Controller")
@RestController
@RequestMapping("/xh/city")
public class XhCityController extends BaseController {

    @Autowired
    private IXhCityService xhCityService;

    /**
     * 查询城市列表
     */
    @PreAuthorize("@ss.hasPermi('xh:city:list')")
    @GetMapping("/list")
    @ApiOperation("查询城市列表")
    public TablePageDataInfo<XhCity> list(XhCity xhCity) {
        return TablePageDataInfo.success(xhCityService.selectXhCityList(xhCity));
    }

    /**
     * 获取城市详细信息
     */
    @PreAuthorize("@ss.hasPermi('xh:city:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取城市详细信息")
    public CommentResult<XhCity> getInfo(@PathVariable("id") Long id) {
        return CommentResult.success(xhCityService.selectXhCityById(id));
    }

    /**
     * 新增城市
     */
    @PreAuthorize("@ss.hasPermi('xh:city:add')")
    @Log(title = "城市", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增城市")
    public CommentResult<XhCity> add(@RequestBody XhCity xhCity) {
            xhCityService.insertXhCity(xhCity);
        return CommentResult.success();
    }

    /**
     * 修改城市
     */
    @PreAuthorize("@ss.hasPermi('xh:city:edit')")
    @Log(title = "城市", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改城市")
    public CommentResult<XhCity> edit(@RequestBody XhCity xhCity) {
            xhCityService.updateXhCity(xhCity);
        return CommentResult.success();
    }

    /**
     * 删除城市
     */
    @PreAuthorize("@ss.hasPermi('xh:city:remove')")
    @Log(title = "城市", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除城市")
    public CommentResult<XhCity> remove(@PathVariable Long[] ids) {
            xhCityService.deleteXhCityByIds(ids);
        return CommentResult.success();
    }
}
